package com.du.dupload;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;

public class SwingContainer {
	private JPanel browserPane;
	private JPanel bars;
	private JFrame frame;
	private SwingMenu menu;
	private FilesAutoAdd autoAdd;
	private JCheckBox restartCheck = new JCheckBox("Restart on stop");
	private static boolean restart = true;
	/**
	 * Text area in which text is loaded
	 */
	private JTextArea taText;

	/**
	 * Loading progress indicator
	 */
	// private JProgressBar pb;

	/**
	 * Loading status popup
	 */
	private JPanel popup;

	public SwingContainer() {
		frame = new JFrame();
		frame.setSize(912, 500);
		frame.setIconImage(Toolkit.getDefaultToolkit().getImage(
				SwingContainer.class.getResource("/res/torrent.png")));
		JPanel cp = new JPanel();
		cp.setLayout(new GridBagLayout());
		frame.setContentPane(cp);
		menu = new SwingMenu();
		frame.setJMenuBar(menu);

		GridBagConstraints gbc = new GridBagConstraints(0, 0, 1, 2, 1., 6.,
				GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5,
						15, 5, 5), 0, 0);
		JPanel browserPane = new SwingBrowsePanel();
		cp.add(browserPane, gbc);

		GridBagConstraints gbc2 = new GridBagConstraints(1, 0, 1, 1, 6., 5.,
				GridBagConstraints.NORTHEAST, GridBagConstraints.NONE,
				new Insets(15, 5, 5, 5), 0, 0);
		// pb = new JProgressBar();
		bars = new JPanel();
		bars.setLayout(new BoxLayout(bars, BoxLayout.Y_AXIS));
		cp.add(bars, gbc2);

		GridBagConstraints gbc3 = new GridBagConstraints(1, 1, 1, 1, 6., 1.,
				GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(
						5, 5, 5, 5), 0, 0);

		cp.add(restartCheck, gbc3);
		restartCheck.setSelected(true);
		restartCheck.addItemListener(new ItemListener() {
			public void itemStateChanged(ItemEvent e) {
				if (e.getStateChange() == ItemEvent.SELECTED) {
					restart = true;
				} else {
					restart = false;
				}
			}
		});

		TasksManager.initializePanel(bars);
		// List<String> al = new ArrayList<String>();
		// al.add("E:\\NBA-Playoffs-20140510-Heat-at-Nets-HD-50fps-RU-mex.mkv");
		// TasksManager.getInstance().addTask(al);
		frame.setVisible(true);
		autoAdd = new FilesAutoAdd();
		autoAdd.start();

	}

	public static boolean getRestart() {
		return restart;
	}

}
